package com.supervision.manage.controller.case

import com.fly.base.common.DataResponse
import com.fly.base.controller.BaseController
import com.supervision.domain.bean.po.SmsPO
import com.supervision.domain.model.SmsTemplate
import com.supervision.manage.service.SmsRecordService
import com.supervision.manage.service.SmsTemplateService
import io.swagger.annotations.Api
import org.springframework.beans.BeanUtils
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestMethod
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.RestController

@RestController
@RequestMapping("manage/1/sms")
@Api(tags = ["短信"])
class SmsController : BaseController() {

    @Autowired
    lateinit var smsTemplateService: SmsTemplateService
    @Autowired
    lateinit var smsRecordService: SmsRecordService

    @RequestMapping("templateList", method = [(RequestMethod.GET)])
    fun list(po: SmsPO): DataResponse {
        val data = smsTemplateService.getSmsTemplateList(po)
        return DataResponse.create().putAll(data)
    }

    @RequestMapping("templateSave", method = [(RequestMethod.POST)])
    fun save(smsTemplate: SmsTemplate): DataResponse {
        var db = SmsTemplate.findById(smsTemplate.id)
        if (db == null) {
            db = SmsTemplate()
        }
        BeanUtils.copyProperties(smsTemplate, db)
        db.save()
        return DataResponse.create()
    }

    @RequestMapping("templateDelete", method = [(RequestMethod.POST)])
    fun delete(@RequestParam id: Long): DataResponse {
        SmsTemplate.findOrFail(id).delete()
        return DataResponse.create()
    }

    @RequestMapping("smsRecordList", method = [(RequestMethod.GET)])
    fun smsRecordList(po: SmsPO): DataResponse {
        smsRecordService.getSmsRecordList(po)
        return DataResponse.create()
    }
}